/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI.GestionEspacioDeportivo;
import Controlador.ControladorEspacioDeportivo;
import Logica.EspacioDeportivo;
import java.awt.HeadlessException;
import javax.swing.JOptionPane;
import java.util.ArrayList;
import java.util.Vector;
import javax.swing.JOptionPane;

/**
 *
 * @author User
 */
public class PanelEspacio extends javax.swing.JPanel {
    ControladorEspacioDeportivo controladorEspacio;
     ArrayList<String> idsEspaciosDeportivos;
    /**
     * Creates new form PanelEspacio
     */
    public PanelEspacio() {
        controladorEspacio = new ControladorEspacioDeportivo();
        idsEspaciosDeportivos = new ArrayList<String>();
        initComponents();
        this.cargarEspaciosDeportivo();
      
    }
    
       private void cargarEspaciosDeportivo()
    {
        this.jCBEspaciosDeportivo.removeAllItems();
        this.jCBEspaciosDeportivo1.removeAllItems();
        Vector<EspacioDeportivo> espacios = (Vector<EspacioDeportivo>) this.controladorEspacio.consultarEspaciosDeportivos();
        
        for(int i=0; i<espacios.size(); i++)
        {
            EspacioDeportivo espacio = espacios.get(i);
            String datosEspacio = "";
            this.idsEspaciosDeportivos.add(espacio.getIdEspacio());
            
            datosEspacio+=espacio.getNombre()+" - "+espacio.getDireccion();
            this.jCBEspaciosDeportivo.addItem(datosEspacio);
            this.jCBEspaciosDeportivo1.addItem(datosEspacio);
            
        }
    }
    private void limpiarDatos()
    {
        this.jTFNombre1.setText("");
        this.jTFDireccion1.setText("");
        this.jTFCapacidad1.setText("");
        this.jTFNombre2.setText("");
        this.jTFDireccion2.setText("");
        this.jTFCapacidad2.setText("");
    }
    
    private void cargarDatosEspacioDeportivo(EspacioDeportivo espacio)
    {
        this.jTFNombre1.setText(espacio.getNombre());
        this.jTFDireccion1.setText(espacio.getNombre());
        this.jTFCapacidad1.setText(""+espacio.getCapacidad());
        this.jTFNombre2.setText(espacio.getNombre());
        this.jTFDireccion2.setText(espacio.getNombre());
        this.jTFCapacidad2.setText(""+espacio.getCapacidad());
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jTFNombre = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jTFDireccion = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jTFCapacidad = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        jPanelDatos = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jTFNombre1 = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jTFCapacidad1 = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jTFDireccion1 = new javax.swing.JTextField();
        jBEditar = new javax.swing.JButton();
        jBCancelar = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        jCBEspaciosDeportivo = new javax.swing.JComboBox();
        jPanel3 = new javax.swing.JPanel();
        jPanelDatos1 = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        jTFNombre2 = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jTFCapacidad2 = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jTFDireccion2 = new javax.swing.JTextField();
        jBEditar1 = new javax.swing.JButton();
        jBCancelar1 = new javax.swing.JButton();
        jLabel11 = new javax.swing.JLabel();
        jCBEspaciosDeportivo1 = new javax.swing.JComboBox();

        jLabel1.setText("Nombre");

        jLabel2.setText("Capacidad");

        jButton2.setText("?");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jLabel3.setText("Dirección");

        jButton1.setText("Guardar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addGap(18, 18, 18)
                                .addComponent(jTFDireccion))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel1))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jTFNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jTFCapacidad, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGap(18, 18, 18)
                        .addComponent(jButton2))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(104, 104, 104)
                        .addComponent(jButton1)))
                .addContainerGap(369, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTFNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTFCapacidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jTFDireccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jButton1)
                .addContainerGap(285, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Crear Espacio Deportivo", jPanel1);

        jLabel4.setText("Nombre");

        jLabel5.setText("Capacidad");

        jLabel6.setText("Dirección");

        jBEditar.setText("Elminar");
        jBEditar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBEditarActionPerformed(evt);
            }
        });

        jBCancelar.setText("Cancelar");
        jBCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBCancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelDatosLayout = new javax.swing.GroupLayout(jPanelDatos);
        jPanelDatos.setLayout(jPanelDatosLayout);
        jPanelDatosLayout.setHorizontalGroup(
            jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelDatosLayout.createSequentialGroup()
                .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelDatosLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5)
                            .addComponent(jLabel4)
                            .addComponent(jLabel6))
                        .addGap(33, 33, 33)
                        .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jTFNombre1, javax.swing.GroupLayout.DEFAULT_SIZE, 210, Short.MAX_VALUE)
                            .addComponent(jTFCapacidad1, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTFDireccion1)))
                    .addGroup(jPanelDatosLayout.createSequentialGroup()
                        .addGap(104, 104, 104)
                        .addComponent(jBEditar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jBCancelar)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanelDatosLayout.setVerticalGroup(
            jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelDatosLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jTFNombre1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jTFCapacidad1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(jTFDireccion1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBEditar)
                    .addComponent(jBCancelar))
                .addContainerGap(240, Short.MAX_VALUE))
        );

        jLabel7.setText("Espacio Deportivo");

        jCBEspaciosDeportivo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCBEspaciosDeportivoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanelDatos, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jCBEspaciosDeportivo, javax.swing.GroupLayout.PREFERRED_SIZE, 313, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 281, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jCBEspaciosDeportivo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanelDatos, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Eliminar Espacio Deportivo", jPanel2);

        jLabel8.setText("Nombre");

        jTFNombre2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTFNombre2ActionPerformed(evt);
            }
        });

        jLabel9.setText("Capacidad");

        jLabel10.setText("Dirección");

        jBEditar1.setText("Editar");
        jBEditar1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBEditar1ActionPerformed(evt);
            }
        });

        jBCancelar1.setText("Cancelar");
        jBCancelar1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBCancelar1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelDatos1Layout = new javax.swing.GroupLayout(jPanelDatos1);
        jPanelDatos1.setLayout(jPanelDatos1Layout);
        jPanelDatos1Layout.setHorizontalGroup(
            jPanelDatos1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelDatos1Layout.createSequentialGroup()
                .addGroup(jPanelDatos1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelDatos1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanelDatos1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanelDatos1Layout.createSequentialGroup()
                                .addComponent(jLabel10)
                                .addGap(18, 18, 18)
                                .addComponent(jTFDireccion2))
                            .addGroup(jPanelDatos1Layout.createSequentialGroup()
                                .addGroup(jPanelDatos1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel9)
                                    .addComponent(jLabel8))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanelDatos1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jTFNombre2, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jTFCapacidad2, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                    .addGroup(jPanelDatos1Layout.createSequentialGroup()
                        .addGap(104, 104, 104)
                        .addComponent(jBEditar1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jBCancelar1)))
                .addContainerGap(404, Short.MAX_VALUE))
        );
        jPanelDatos1Layout.setVerticalGroup(
            jPanelDatos1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelDatos1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelDatos1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(jTFNombre2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelDatos1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(jTFCapacidad2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelDatos1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(jTFDireccion2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanelDatos1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBEditar1)
                    .addComponent(jBCancelar1))
                .addContainerGap(240, Short.MAX_VALUE))
        );

        jLabel11.setText("Espacio Deportivo");

        jCBEspaciosDeportivo1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCBEspaciosDeportivo1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanelDatos1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel11)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jCBEspaciosDeportivo1, javax.swing.GroupLayout.PREFERRED_SIZE, 245, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(jCBEspaciosDeportivo1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanelDatos1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Editar Espacio Deportivo", jPanel3);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1)
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        ConsultarEspaciosDeportivos frameConsultarEspacios = new ConsultarEspaciosDeportivos(null, true);
        frameConsultarEspacios.setVisible(true);
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        try
        {
            int capacidad = Integer.parseInt(this.jTFCapacidad.getText());
            boolean exito;

            if(capacidad < 0)
            {
                JOptionPane.showMessageDialog(this, "El valor de capacidad debe ser un numero entero, no negativo", "Error de tipo", JOptionPane.ERROR_MESSAGE);
            }

            exito = this.controladorEspacio.guardEspacioDeportivo(  this.jTFNombre.getText(),
                capacidad, this.jTFDireccion.getText());
            if(exito)
            {
                JOptionPane.showMessageDialog(this, "La Operación se Realizo con Exito", "Exito", JOptionPane.INFORMATION_MESSAGE);
            }
            else
            {
                JOptionPane.showMessageDialog(this, "Ocurrio un error, intentelo de nuevo", "Error", JOptionPane.ERROR_MESSAGE);
            }
        }
        catch(NumberFormatException | HeadlessException e)
        {
            JOptionPane.showMessageDialog(this, "El valor de capacidad debe ser un numero entero, no negativo", "Error de tipo", JOptionPane.ERROR_MESSAGE);
        }

    }//GEN-LAST:event_jButton1ActionPerformed

    private void jBEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBEditarActionPerformed
        // TODO add your handling code here:
        try
        {
            int indice = this.jCBEspaciosDeportivo.getSelectedIndex();
            String idEspacio = this.idsEspaciosDeportivos.get(indice);

            boolean exito;

            exito = this.controladorEspacio.eliminarEspacioDeportivo(idEspacio);
            if(exito)
            {
                JOptionPane.showMessageDialog(this, "La Operación se Realizo con Exito", "Exito", JOptionPane.INFORMATION_MESSAGE);
            }
        }
        catch(NumberFormatException | HeadlessException e)
        {
            JOptionPane.showMessageDialog(this, "El valor de capacidad debe ser un numero entero, no negativo", "Error de tipo", JOptionPane.ERROR_MESSAGE);
        }
        this.cargarEspaciosDeportivo();
    }//GEN-LAST:event_jBEditarActionPerformed

    private void jBCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBCancelarActionPerformed
        // TODO add your handling code here:
        this.limpiarDatos();
        this.jPanelDatos.setVisible(false);
        this.jCBEspaciosDeportivo.setEnabled(true);
    }//GEN-LAST:event_jBCancelarActionPerformed

    private void jCBEspaciosDeportivoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCBEspaciosDeportivoActionPerformed
        // TODO add your handling code here:
        int indice = this.jCBEspaciosDeportivo.getSelectedIndex();
        String idEspacio = this.idsEspaciosDeportivos.get(indice);
        EspacioDeportivo espacio = this.controladorEspacio.consultarEspacioDeportivo(idEspacio);
        this.cargarDatosEspacioDeportivo(espacio);
        this.jPanelDatos.setVisible(true);
        this.jCBEspaciosDeportivo.setEnabled(false);

    }//GEN-LAST:event_jCBEspaciosDeportivoActionPerformed

    private void jBEditar1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBEditar1ActionPerformed
        // TODO add your handling code here:
        try
        {
            int capacidad = Integer.parseInt(this.jTFCapacidad.getText());
            int indice = this.jCBEspaciosDeportivo.getSelectedIndex();
            String idEspacio = this.idsEspaciosDeportivos.get(indice);

            boolean exito;

            if(capacidad > 0)
            {
                JOptionPane.showMessageDialog(this, "El valor de capacidad debe ser un numero entero, no negativo", "Error de tipo", JOptionPane.ERROR_MESSAGE);
            }

            exito = this.controladorEspacio.editarEspacioDeportivo( idEspacio, this.jTFNombre.getText(),
                capacidad, this.jTFDireccion.getText());
            if(exito)
            {
                JOptionPane.showMessageDialog(this, "La Operación se Realizo con Exito", "Exito", JOptionPane.INFORMATION_MESSAGE);
            }
        }
        catch(NumberFormatException | HeadlessException e)
        {
            JOptionPane.showMessageDialog(this, "El valor de capacidad debe ser un numero entero, no negativo", "Error de tipo", JOptionPane.ERROR_MESSAGE);
        }
        this.cargarEspaciosDeportivo();
    }//GEN-LAST:event_jBEditar1ActionPerformed

    private void jBCancelar1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBCancelar1ActionPerformed
        // TODO add your handling code here:
        this.limpiarDatos();
        this.jPanelDatos.setVisible(false);
        this.jCBEspaciosDeportivo.setEnabled(true);
    }//GEN-LAST:event_jBCancelar1ActionPerformed

    private void jCBEspaciosDeportivo1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCBEspaciosDeportivo1ActionPerformed
        // TODO add your handling code here:
        int indice = this.jCBEspaciosDeportivo.getSelectedIndex();
        String idEspacio = this.idsEspaciosDeportivos.get(indice);
        EspacioDeportivo espacio = this.controladorEspacio.consultarEspacioDeportivo(idEspacio);
        this.cargarDatosEspacioDeportivo(espacio);
        this.jPanelDatos.setVisible(true);
        this.jCBEspaciosDeportivo.setEnabled(false);

    }//GEN-LAST:event_jCBEspaciosDeportivo1ActionPerformed

    private void jTFNombre2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTFNombre2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTFNombre2ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBCancelar;
    private javax.swing.JButton jBCancelar1;
    private javax.swing.JButton jBEditar;
    private javax.swing.JButton jBEditar1;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JComboBox jCBEspaciosDeportivo;
    private javax.swing.JComboBox jCBEspaciosDeportivo1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanelDatos;
    private javax.swing.JPanel jPanelDatos1;
    private javax.swing.JTextField jTFCapacidad;
    private javax.swing.JTextField jTFCapacidad1;
    private javax.swing.JTextField jTFCapacidad2;
    private javax.swing.JTextField jTFDireccion;
    private javax.swing.JTextField jTFDireccion1;
    private javax.swing.JTextField jTFDireccion2;
    private javax.swing.JTextField jTFNombre;
    private javax.swing.JTextField jTFNombre1;
    private javax.swing.JTextField jTFNombre2;
    private javax.swing.JTabbedPane jTabbedPane1;
    // End of variables declaration//GEN-END:variables
}
